package net.hanjava.roas;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

public class Book2Bundles {
    private String sourceXLS;

    private File outputDir;

    /**
     * @param xlsPath http URL or local path for source xls file
     * @param outputDir output directory path(local)
     * @throws MalformedURLException 
     */
    public Book2Bundles(String xlsPath, String outputDir) {
        sourceXLS = xlsPath;
        this.outputDir = new File(outputDir);
    }

    public void generate() throws IOException {
        XlsBook workbook = new XlsBook(sourceXLS);
        int sc = workbook.getSheetCount();
        for(int i = 0; i < sc; i++) {
            ResourceSheet rSheet = new XlsResourceSheet(workbook, i);
            PropertiesGenerator pGen = new PropertiesGenerator(rSheet, outputDir);
            pGen.generate();
        }
    }

    public static void main(String[] args) throws Exception {
        System.out.println("ROAS Book-to-bundles");
        System.out.println("converts xls file to sets of properties files");
        System.out.println("Each sheet will be converted to '*.properties' files");

        if(args.length != 2) {
            System.out.println("Usage : b2b xlspath outputdir");
            System.exit(-1);
        }
        String xlsPath = args[0];
        String outputDir = args[1];
        Book2Bundles b2b = new Book2Bundles(xlsPath, outputDir);
        b2b.generate();
    }
}